package com.bjpowernode.boss.mvc.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjpowernode.boss.PowerBossApplication;
import com.bjpowernode.boss.dao.entity.PayWay;
import com.bjpowernode.boss.dao.mapper.PayWayMapper;
import com.bjpowernode.boss.dao.result.DicEntity;
import com.bjpowernode.boss.mvc.service.PayWayService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yu
 * @date 2024/7/12  22:39
 */
@Service
public class PayWayServiceImpl implements PayWayService {

    @Resource
    private PayWayMapper payWayMapper ;

    @Override
    public IPage<PayWay> pageList(Integer pageNo, Integer pageSize, String productCode) {
        QueryWrapper<PayWay> wrapper = new QueryWrapper<>() ;
        wrapper.orderByAsc("pay_product_code").orderByDesc("way_code").orderByAsc("type_code") ;

        if (StrUtil.isNotBlank(productCode)) {
            wrapper.eq("pay_product_code", productCode.trim()) ;
        }

        IPage<PayWay> payWayIPage = payWayMapper.selectPage(Page.of(pageNo, pageSize), wrapper) ;

        return payWayIPage ;
    }

    @Override
    public List<DicEntity> getPayWayDicListFromCache() {
        return PowerBossApplication.PAYWAY_DIC_LIST;
    }

    @Override
    public List<DicEntity> getPayWayTypeDicListFromCache(String payWayCode) {
        List<DicEntity> dicEntityList = PowerBossApplication.PAYTYPE_DIC_MAP.get(payWayCode);
        return dicEntityList == null ? new ArrayList<>() : dicEntityList ;
    }
}
